package com.cskaoyan._03jdbc.dev;

import com.cskaoyan._03jdbc.util.JdbcUtils;

import java.sql.*;

/**
 * @author Macro_Ray
 * @since 2024/4/17 下午4:02
 */
public class JdbcBasicFormat_v2 {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            // 3.发送sql语句
            connection = JdbcUtils.getConnection();
            statement = connection.createStatement();
            resultSet = statement.executeQuery("select * from student");
            // 4.解析结果集
            resultSet.next();
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int chinese = resultSet.getInt("chinese");
            int english = resultSet.getInt("english");
            int math = resultSet.getInt("math");
            Date birthday = resultSet.getDate("birthday");
            String place = resultSet.getString("place");
            System.out.println(id + " " + name + " " + chinese + " " + english + " " + math + " " + birthday + " " + place);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            // 5.关闭连接
            try {
                JdbcUtils.close(connection, statement, resultSet);
            } catch (SQLException e) {

            }
        }
    }
}

